package main.chapter4;/**
 * @Author xy
 * @Date 2020/6/10 22:11
 * @Description
 */

/**
 * 文件名称： main.chapter4.StaticTest.java</br>
 * 初始作者： xy</br>
 * 创建日期： 2020/6/10 22:11</br>
 * 功能说明： TODO <br/>
 * =================================================<br/>
 * 修改记录：<br/>
 * 修改作者        日期       修改内容<br/>
 * ================================================<br/>
 * Copyright (c) 2020-2021 .All rights reserved.<br/>
 */
public class StaticTest {
    public static void main(String[] args) {
        Employee[] staff = new Employee[3];
        staff[0] = new Employee("Tom",40000);
        staff[1] = new Employee("Dick",60000);
        staff[2] = new Employee("Harry",50000);
        for (Employee employee : staff){
            employee.setId();
            System.out.println("name="+ employee.getName()+",id="+employee.getId()+",salary="+ employee.getSalary());
        }
        int n = Employee.getNextId();
        System.out.println("Next available id="+n);
    }


}

class Employee{
    private static int nextId = 1;

    private String name;
    private double salary;
    private int id;

    public Employee(String name, double salary) {
        this.name = name;
        this.salary = salary;
        this.id = 0;
    }

    public String getName() {
        return name;
    }


    public double getSalary() {
        return salary;
    }

    public int getId() {
        return id;
    }

    public void setId() {
        id=nextId;
        nextId++;
    }

    public static int getNextId(){
        return nextId;
    }

    public static void main(String[] args) {
        Employee employee = new Employee("Harry", 50000);
        System.out.println(employee.getName()+" "+ employee.getSalary());
    }
}
